package com.songcha.module_vip.ui.adapter

import android.graphics.Color
import android.graphics.Paint
import android.view.View
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.songcha.library_common.util.LogUtil
import com.songcha.library_common.util.StringUtil
import com.songcha.library_common.util.ToastUtil
import com.songcha.library_common.util.dp2px
import com.songcha.module_vip.databinding.VipItemVipRechargePriceBinding
import com.songcha.module_vip.R
import com.songcha.module_vip.bean.vip.VipRechargePriceDataBean


class VipRechargePriceAdapter<DB: ViewDataBinding>(val mIsFirst:Boolean,list:MutableList<VipRechargePriceDataBean.VipRechargePriceBean.OpenVipBean>):BaseQuickAdapter<VipRechargePriceDataBean.VipRechargePriceBean.OpenVipBean, BaseDataBindingHolder<DB>>(
    R.layout.vip_item_vip_recharge_price,list) {
    var selectIndex=0

    init {
        /*setOnItemClickListener{a,v,p->
            selectIndex=p
            notifyDataSetChanged()
        }*/
    }

    override fun convert(holder: BaseDataBindingHolder<DB>, item: VipRechargePriceDataBean.VipRechargePriceBean.OpenVipBean) {
        val binding=holder.dataBinding as VipItemVipRechargePriceBinding
        var money=item.ordinaryMoney
        if(mIsFirst && item.firstMoney>0f){
            money=item.firstMoney
            binding.vipFlFirstPreferential.visibility= View.VISIBLE
        }else{
            binding.vipFlFirstPreferential.visibility= View.GONE
        }
        binding.vipTvMonth.text="${item.monthNumber}个月"
        binding.vipTvOriginPrice.apply {
            paintFlags=(paintFlags or Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG)
            text="折合${StringUtil.float2PlainString(money/item.monthNumber,"0.00",true)}元/月"
        }
        binding.vipTvPrice.text=StringUtil.float2PlainString(money)

        if(holder.absoluteAdapterPosition==selectIndex){
            binding.vipCcl.setBorder(Color.parseColor("#EDB407"),1f.dp2px())
            binding.vipCcl.setContainerBackgroundColor(Color.parseColor("#19EDB407"))
            binding.vipIvSelect.visibility= View.VISIBLE
        }else{
            binding.vipCcl.setBorder(Color.parseColor("#C5C0CA"),1f.dp2px())
            binding.vipCcl.setContainerBackgroundColor(Color.WHITE)
            binding.vipIvSelect.visibility= View.GONE
        }

    }

}